﻿Imports System.Data.SqlClient

Public Class cControl

    Dim con As New SqlConnection(strcon)

    Public Sub getCombo(ByVal Combo As ComboBox, ByVal sql As String, _
                          ByVal dMember As String, ByVal vMember As String)
        Dim oMain As New cMain
        Combo.DataSource = oMain.getData(sql)
        Combo.DisplayMember = dMember
        Combo.ValueMember = vMember
    End Sub

    Public Sub dgvHeader(ByVal header As String, ByVal dgv As DataGridView)
        Dim sum As Integer = 0
        Dim ColName As String, W As Integer
        Dim Col() As String
        Col = Split(header, "|")
        Dim Colx() As String
        Dim i As Integer
        For i = 0 To UBound(Col)
            Colx = Split(Col(i), ";")
            ColName = Colx(0)
            W = Val(Colx(1))
            sum = sum + W
            If i = UBound(Col) Then
                If sum > dgv.Width Then
                    dgv.Columns(i).HeaderText = ColName
                    dgv.Columns(i).Width = W
                Else
                    dgv.Columns(i).HeaderText = ColName
                    dgv.Columns(i).AutoSizeMode = DataGridViewAutoSizeColumnsMode.Fill
                End If
            Else
                dgv.Columns(i).HeaderText = ColName
                dgv.Columns(i).Width = W
            End If
        Next
    End Sub

    Public Function checknull(ByVal Data As String) As Boolean
        If Data <> "" Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function getID(ByVal ColumnID As String, ByVal Table As String) As Long
        Dim ID As Long
        Dim st As String
        Dim cmd As New SqlCommand
        cmd.CommandText = "SELECT MAX(" & ColumnID & ") FROM " & Table & ""
        cmd.Connection = con
        Try
            con.Open()
            st = cmd.ExecuteScalar
            ID = CInt(st)
        Catch ex As Exception
            ID = 0
        Finally
            ID += 1
            con.Close()
            cmd.Dispose()
        End Try

        Return ID
    End Function

End Class
